﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Business.vo;
using Business.exception;

namespace Business.dao
{
    internal class SponsorDao : AbstractDao
    {

        public Sponsor GetById(Int32 id)
        {
            Sponsor sponsor = null;

            try
            {
                sponsor = mapper.QueryForObject<Sponsor>("Sponsor.selectById", id);

            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving user from database", ex);
            }

            return sponsor;
        }

        public IList<Sponsor> GetAll()
        {
            IList<Sponsor> sponsors = null;

            try
            {
                sponsors = mapper.QueryForList<Sponsor>("Sponsor.selectAll", null);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving users from database", ex);
            }

            return sponsors;
        }

        public IList<Sponsor> GetAllNames()
        {
            IList<Sponsor> sponsors = null;

            try
            {
                sponsors = mapper.QueryForList<Sponsor>("Sponsor.selectAllNames", null);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving users from database", ex);
            }

            return sponsors;
        }
        

        public void Save(Sponsor sponsor)
        {
            try
            {
                mapper.Insert("Sponsor.insert", sponsor);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving users from database", ex);
            }
        }


        public void Update(Sponsor sponsor)
        {
            try
            {
                mapper.Update("Sponsor.update", sponsor);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving users from database", ex);
            }
        }

        public void Delete(Int32 id)
        {
            try
            {
                mapper.Delete("Sponsor.deleteById", id);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving users from database", ex);
            }
        }
    }
}
